package com.neuedu.api.collection;

import java.sql.Array;
import java.util.*;

/**
 * @author 金山
 * 项目：javase
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/10/2815:33
 */
public class MyCollectionException {


    public static void main(String[] args) {

        // List list1 = Arrays.asList(new Integer(100),"abcd","abcde","dsfasfsa");
        List list1 = Arrays.asList(100,"abcd","abcde","dsfasfsa");

        // java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String
        // String item0 = (String) list1.get(0);
        // System.out.println("item0.length() = " + item0.length());


        //java.lang.ClassCastException: class com.neuedu.api.collection.Student cannot be cast to class java.lang.String (
        // Object obj1 = new Student();
        // System.out.println("(String)obj1 = " + (String) obj1);


        //Arrays.ArrayList 没有重写  add方法      UnsupportedOperationException
        // list1.add("4");
        //
        // System.out.println("list1 = " + list1);
        //
        //
        for(Iterator it = list1.iterator();    it.hasNext() ;){

            Object item = it.next();
            System.out.println("item.getClass().getName() = " + item.getClass().getName());
            if(item.getClass().getName() == "java.lang.Integer"){
                //Exception in thread "main" java.lang.UnsupportedOperationException: remove
                // list1.remove(item);
            }
        }

        // System.out.println("list1.size() = " + list1.size());
        //
        // /java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 4
        // System.out.println("list1.get(100) = " + list1.get(100));
        //
        //
        //
        LinkedList list2 = new LinkedList(list1);

        System.out.println("list2.pop() = " + list2.pop());
        System.out.println("list2.pop() = " + list2.pop());
        System.out.println("list2.pop() = " + list2.pop());
        System.out.println("list2.pop() = " + list2.pop());
        //
        // //main" java.util.NoSuchElementException
        // System.out.println("list2.pop() = " + list2.pop());






    }

}
